@extends('web.frame_layout')
<link rel="stylesheet" href="{{asset('web/css/components.css')}}">
<link rel="stylesheet" href="{{asset('web/css/my-recommend.css')}}">
<link rel="stylesheet" href="{{asset('web/css/popup.css')}}">
<link rel="stylesheet" href="//at.alicdn.com/t/font_rp32h1das28uayvi.css">
<?php $parent_menu = "会员管理";$menu_selected = "会员激活";?>

@section('content')
    <div class="m-right-nr">
        <div>
            <h2><span>会员激活</span></h2>
        </div>
        <div class="m-VList">
            <div class="m-VList-title">
                {{--会员列表--}}
                <div>
                    <form action="{{route('web.users')}}" method="get" id="txjl_search">
                        <input type="text" name="search" placeholder="请输入用户名进行精准查询">
                        <button>搜索</button>
                    </form>
                </div>
            </div>

            <div class="table-responsive">
                <table class="table">
                    <tr>
                        <th>会员编号</th>
                        <th>会员用户名</th>
                        <th>会员等级</th>
                        <th>接点人</th>
                        <th>接点位置</th>
                        <th>推荐人</th>
                        <th>状态</th>
                        <th>注册时间</th>
                        <th>管理</th>
                    </tr>
                    @foreach($users as $user)
                        <tr class="active">
                            <td>{{$user->no}}</td>
                            <td>{{$user->username}}</td>
                            <td>
                                {{\App\VModels\VVip::vipBySlug($user->vip_slug)->name}}
                            </td>
                            <td>{{$user->nuser->username or "无"}}</td>
                            <td>
                                @if($user->addr == \App\Models\MUser::$ADDR_A)
                                    A区
                                @elseif($user->addr == \App\Models\MUser::$ADDR_B)
                                    B区
                                @endif
                            </td>
                            <td>{{$user->puser->username or "无"}}</td>
                            <td>{{uStatusStr($user->status)}}</td>
                            <td>{{date("Y-m-d",$user->reg_time)}}</td>
                            <td>
                                @if($user->ok_status == \App\Models\MUser::$STATUS_NOACTIVATED)
                                    <a class="add_V" href="javascript:void(0)" data="{{$user->id}}" money="{{\App\VModels\VVip::attrBySlug($user->vip_slug)[\App\Models\MUser::$ATTR_ACTIVE]}}">激活</a>
                                    {{--href="{{route('web.users.activation',['id'=>$user->id])}}">激活</a>--}}
                                    <a class="del_V" href="javascript:void(0)" data="{{$user->id}}">删除</a>
                                    {{--                                    <a class="del_V" href="{{route('sys.users.del',['id'=>$user->id])}}">删除</a>--}}
                                @endif
                            </td>
                        </tr>
                    @endforeach
                </table>
                @include('web.coms.fenye')
            </div>
        </div>
    </div>
    <!--popup-->
    <div class="popup_cnt" id="popup_cnt">
        <form action="{{route('web.users.activation')}}" id="jhfs" method="post" onsubmit="return false;">
            {!! csrf_field() !!}
            <span style="color:black;font-size: 16px;">{{uWalletStr(2)}}钱包: <span style="color:red">{{$self->wallet->w2}}</span></span><br>
            <span style="color:black;font-size: 16px;">{{uWalletStr(1)}}钱包: <span style="color:red">{{$self->wallet->w1}}</span></span><br>
            <p>激活方式：</p>
            @if (isset($user))
            <select name="activate_way" id="activate_way">
                <option value="">请选择激活方式</option>
                <option value="1"></option>
                <option value="2"></option>
            </select>
            @endif
            <p>交易密码：</p>
            <input type="password" name="safepass" id="safepass" placeholder="请输入交易密码">
        </form>
    </div>


@endsection

@section('footer')
    <script TYPE="text/javascript">

        //    会员激活弹出框
        $('.add_V').on('touchend click', function (e) {
            e.preventDefault();

            var form = $("#jhfs");          //表单元素
            var id = $(this).attr('data');  //用户ID
            var url = form.attr('action') + "/" + id;  //表单提交地址
            var first = true;   //阻止二次提交
            var allMoney = $(this).attr('money');
//            $('option[value="1"]').html(`(100%)报单币激活 (${allMoney})`);
            $('option[value="1"]').html("(100%){{uWalletStr(2)}}激活 ("+allMoney+")");
            $('option[value="2"]').html("({{cv("bonus.jh_jjb")}}%){{uWalletStr(1)}}("+{{cv("bonus.jh_jjb")*0.01}}*allMoney+") + ({{cv("bonus.jh_bdb")}}%){{uWalletStr(2)}}激活("+{{cv("bonus.jh_bdb")*0.01}}*allMoney+")");

            layer.open({
                type: 1,
                skin: 'layui-layer-molv',
                title: "会员激活",
                area: '350px',
                content: $('#popup_cnt'),
                btn: ['立即激活'],
                btnAlign: 'c',
                yes: function (index,layero) {
                    if ($("#activate_way").val() == '') {
                        layer.msg('请选择激活方式', {time: 1500, icon: 0});
                        return false;
                    }
                    if ($("#safepass").val() == '') {
                        layer.msg('请输入交易密码', {time: 1500, icon: 0});
                        return false;
                    }

                   $('.layui-layer-btn0').attr('href','javascript:void(0)');

                    if (first) {
                        form.ajaxSubmit({
                            type: "POST",
                            url: url,
                            dataType: "json",
                            data: form.serialize(),
                            success: function (data) {
                                first = false;
                                if (data.code == 0) {
                                    layer.close(index);
                                    toastr.success(data.msg);
                                    setInterval(function () {
                                        window.location.reload();
                                    }, 1500);
                                }
                                if (data.code == 1) {
                                    layer.close(index);
                                    toastr.error(data.msg);
//                                    layer.msg(data.msg,{
//                                        icon:5
//                                        ,time:2000
//                                        ,anim:6
//                                    });
                                    setInterval(function () {
                                        window.location.reload();
                                    }, 1500);
                                }
                            }
                        });
                    }

                }
            });
            $('.layui-layer-btn').addClass('btnOnly')
        });

        //    会员删除
        $('.del_V').on('touchend click', function (e) {
            e.preventDefault();
            var id = $(this).attr('data');  //用户ID
            layer.open({
                skin: 'layui-layer-molv',
                title: "会员删除",
                area: '300px',
                content: "你确定要删除此会员吗？",
                btn: ['确定', '取消'],
                btnAlign: 'c',
                yes: function (index) {
                    var url = "{{route('web.users.del')}}" + "/" + id;
                    window.location.href = url;
                    layer.close(index);
                }
            });
        });

        function preventDefa(e) {
            if (window.event) {
                //IE中阻止函数器默认动作的方式
                window.event.returnValue = false;
            }
            else {
                //阻止默认浏览器动作(W3C)
                e.preventDefault();
            }
        }
    </script>
@endsection